module RegisterFile #(ADDR_WIDTH = 5, DATA_WIDTH = 64, REG_NUM = 32) (
  input clk,
  input rst,
  input [DATA_WIDTH-1:0] wdata,
  input [ADDR_WIDTH-1:0] waddr,
  input [ADDR_WIDTH-1:0] raddrA,
  input [ADDR_WIDTH-1:0] raddrB,
  input wen,
  output reg [DATA_WIDTH-1:0] rdataA,
  output reg [DATA_WIDTH-1:0] rdataB
);

  export "DPI-C" function read_rf;

  reg [DATA_WIDTH-1:0] rf [REG_NUM-1:0];

  assign rdataA = rf[raddrA];
  assign rdataB = rf[raddrB];

  integer i = 0;
  always @(posedge clk) begin
    if (rst) begin 
      for (i = 0; i < REG_NUM; i = i+1) begin
        rf[i] <= {DATA_WIDTH{1'b0}};
      end
    end else if (wen && waddr != 0) begin
      rf[waddr] <= wdata;
    end
  end

  function void read_rf(output longint unsigned target [REG_NUM-1:0]);
    int j = 0;
    for (j = 0; j < REG_NUM; j++) begin
      target[j] = rf[j];
    end
  endfunction: read_rf

endmodule